package com.junjiao.util.test;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;

/**
 * 抽象测试基类 用于Spring事务相关单元测试
 * 
 * @author jicheng
 * @version $Revision$ 2012-2-10
 * @author (lastest modification by $Author$)
 */
public abstract class AbstractTestCase extends
		AbstractTransactionalDataSourceSpringContextTests {
	// @Autowired //注入指定的数据源
	@Override
	@Resource(name = "dataSource")
	public void setDataSource(DataSource dataSource) {
		super.setDataSource(dataSource);
	}

	/**
	 * 获取Spring Context文件路径 {@inheritDoc}
	 * 
	 * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations()
	 */
	protected String[] getConfigLocations() {
		return new String[] { "classpath:applicationContext*.xml" };
	}

	/**
	 * 事务回滚前测试完成后的清理，运行时仅加载一次
	 * 
	 * @see org.springframework.test.AbstractTransactionalSpringContextTests#onTearDownInTransaction()
	 */
	public void onTearDownInTransaction() {
	}

	protected void prepareTestInstance() throws Exception {
		setAutowireMode(AUTOWIRE_BY_NAME);
		setDependencyCheck(false);
		super.prepareTestInstance();
	}

}
